/*     */ package com.zimbra.cs.util.tnef.mapi;
/*     */ 
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.util.tnef.IcalUtil;
/*     */ import com.zimbra.cs.util.tnef.TNEFtoIcalendarServiceException;
/*     */ import java.io.IOException;
/*     */ import java.util.EnumSet;
/*     */ import net.fortuna.ical4j.model.DateTime;
/*     */ import net.freeutils.tnef.RawInputStream;
/*     */ import net.freeutils.tnef.TNEFUtils;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ChangedInstanceInfo
/*     */ {
/*  33 */   static Log sLog = ZimbraLog.tnef;
/*     */   private String oemCodePage;
/*     */   private int exceptionNum;
/*     */   private TimeZoneDefinition tz;
/*     */   private long startMinsSince1601;
/*     */   private long endMinsSince1601;
/*     */   private long origStartMinsSince1601;
/*     */   private String subject;
/*     */   private long apptColor;
/*     */   private long subType;
/*     */   private long attachment;
/*     */   private long busyStatus;
/*     */   private String location;
/*     */   private long reminderSet;
/*     */   private long reminderDelta;
/*     */   private long meetingType;
/*     */   private EnumSet<ExceptionInfoOverrideFlag> overrideFlags;
/*     */   private boolean hasExtendedInfo;
/*     */   private boolean hasChangeHighlight;
/*     */   private long changeHighlightSize;
/*     */   private long changeHighlightValue;
/*     */   private byte[] chgHLReserved;
/*     */   private long rsrvBlockEE1Size;
/*     */   private byte[] rsrvBlockEE1;
/*     */   private long eeStartMinsSince1601;
/*     */   private long eeEndMinsSince1601;
/*     */   private long eeOrigStartMinsSince1601;
/*     */   private int unicodeSubjectLen;
/*     */   private String unicodeSubject;
/*     */   private int unicodeLocationLen;
/*     */   private String unicodeLocation;
/*     */   private long rsrvBlockEE2Size;
/*     */   private byte[] rsrvBlockEE2;
/*     */   
/*     */   public ChangedInstanceInfo(int num, TimeZoneDefinition tzDef, String oemCP)
/*     */   {
/*  69 */     this.oemCodePage = oemCP;
/*  70 */     this.exceptionNum = num;
/*  71 */     this.tz = tzDef;
/*  72 */     this.startMinsSince1601 = 0L;
/*  73 */     this.endMinsSince1601 = 0L;
/*  74 */     this.origStartMinsSince1601 = 0L;
/*  75 */     this.subject = null;
/*  76 */     this.apptColor = 0L;
/*  77 */     this.subType = 0L;
/*  78 */     this.attachment = 0L;
/*  79 */     this.busyStatus = BusyStatus.BUSY.mapiPropValue();
/*  80 */     this.location = null;
/*  81 */     this.reminderSet = 0L;
/*  82 */     this.reminderDelta = 0L;
/*  83 */     this.meetingType = 0L;
/*  84 */     this.overrideFlags = EnumSet.noneOf(ExceptionInfoOverrideFlag.class);
/*  85 */     this.hasExtendedInfo = false;
/*  86 */     this.hasChangeHighlight = false;
/*  87 */     this.changeHighlightSize = -1L;
/*  88 */     this.changeHighlightValue = 0L;
/*  89 */     this.chgHLReserved = null;
/*  90 */     this.rsrvBlockEE1Size = -1L;
/*  91 */     this.rsrvBlockEE1 = null;
/*  92 */     this.eeStartMinsSince1601 = -1L;
/*  93 */     this.eeEndMinsSince1601 = -1L;
/*  94 */     this.eeOrigStartMinsSince1601 = -1L;
/*  95 */     this.unicodeSubjectLen = 0;
/*  96 */     this.unicodeSubject = null;
/*  97 */     this.unicodeLocationLen = 0;
/*  98 */     this.unicodeLocation = null;
/*  99 */     this.rsrvBlockEE2Size = -1L;
/* 100 */     this.rsrvBlockEE2 = null;
/*     */   }
/*     */   
/*     */   public void readExceptionInfo(RawInputStream ris) throws IOException, TNEFtoIcalendarServiceException {
/* 104 */     this.startMinsSince1601 = ris.readU32();
/* 105 */     this.endMinsSince1601 = ris.readU32();
/* 106 */     this.origStartMinsSince1601 = ris.readU32();
/* 107 */     int overrides = ris.readU16();
/* 108 */     for (ExceptionInfoOverrideFlag flag : ExceptionInfoOverrideFlag.values()) {
/* 109 */       if ((overrides & flag.mapiPropValue()) == flag.mapiPropValue()) {
/* 110 */         this.overrideFlags.add(flag);
/*     */       }
/*     */     }
/* 113 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_SUBJECT)) {
/* 114 */       int subjectLenPlus1 = ris.readU16();
/* 115 */       int subjectLen = ris.readU16();
/* 116 */       if (subjectLenPlus1 != subjectLen + 1) {
/* 117 */         throw TNEFtoIcalendarServiceException.RECURDEF_BAD_CHANGED_SUBJ("Specified len=" + subjectLen + " len+1=" + subjectLenPlus1);
/*     */       }
/*     */       
/* 120 */       this.subject = IcalUtil.readString(ris, subjectLen, this.oemCodePage);
/*     */     }
/* 122 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_MEETINGTYPE)) {
/* 123 */       this.meetingType = ris.readU32();
/*     */     }
/* 125 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_REMINDERDELTA)) {
/* 126 */       this.reminderDelta = ris.readU32();
/*     */     }
/* 128 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_REMINDER)) {
/* 129 */       this.reminderSet = ris.readU32();
/*     */     }
/* 131 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_LOCATION)) {
/* 132 */       int locLenPlus1 = ris.readU16();
/* 133 */       int locLen = ris.readU16();
/* 134 */       if (locLenPlus1 != locLen + 1) {
/* 135 */         throw TNEFtoIcalendarServiceException.RECURDEF_BAD_CHANGED_LOC("Specified len=" + locLen + " len+1=" + locLenPlus1);
/*     */       }
/*     */       
/* 138 */       this.location = IcalUtil.readString(ris, locLen, this.oemCodePage);
/*     */     }
/* 140 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_BUSYSTATUS)) {
/* 141 */       this.busyStatus = ris.readU32();
/*     */     }
/* 143 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_ATTACHMENT)) {
/* 144 */       this.attachment = ris.readU32();
/*     */     }
/* 146 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_SUBTYPE)) {
/* 147 */       this.subType = ris.readU32();
/*     */     }
/* 149 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_APPTCOLOR)) {
/* 150 */       this.apptColor = ris.readU32();
/*     */     }
/*     */   }
/*     */   
/*     */   public void readExtendedException(RawInputStream ris, boolean hasChangeHighlight) throws IOException
/*     */   {
/* 156 */     this.hasChangeHighlight = hasChangeHighlight;
/* 157 */     this.hasExtendedInfo = true;
/* 158 */     if (hasChangeHighlight) {
/* 159 */       this.changeHighlightSize = ris.readU32();
/* 160 */       this.changeHighlightValue = ris.readU32();
/* 161 */       this.chgHLReserved = ris.readBytes((int)this.changeHighlightSize - 4);
/*     */     }
/* 163 */     this.rsrvBlockEE1Size = ris.readU32();
/* 164 */     this.rsrvBlockEE1 = ris.readBytes((int)this.rsrvBlockEE1Size);
/* 165 */     if ((this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_SUBJECT)) || (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_LOCATION)))
/*     */     {
/* 167 */       this.eeStartMinsSince1601 = ris.readU32();
/* 168 */       this.eeEndMinsSince1601 = ris.readU32();
/* 169 */       this.eeOrigStartMinsSince1601 = ris.readU32();
/* 170 */       if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_SUBJECT)) {
/* 171 */         this.unicodeSubjectLen = ris.readU16();
/* 172 */         this.unicodeSubject = ris.readStringUnicode(this.unicodeSubjectLen * 2);
/*     */       }
/* 174 */       if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_LOCATION)) {
/* 175 */         this.unicodeLocationLen = ris.readU16();
/* 176 */         this.unicodeLocation = ris.readStringUnicode(this.unicodeLocationLen * 2);
/*     */       }
/*     */       
/*     */ 
/* 180 */       this.rsrvBlockEE2Size = ris.readU32();
/* 181 */       this.rsrvBlockEE2 = ris.readBytes((int)this.rsrvBlockEE2Size);
/*     */     }
/*     */   }
/*     */   
/*     */   public String toString() {
/* 186 */     StringBuffer buf = new StringBuffer("    ChangedInstance:").append(this.exceptionNum).append("\n");
/*     */     
/* 188 */     infoOnLocalTimeSince1601Val(buf, "        StartDate:", this.startMinsSince1601);
/*     */     
/* 190 */     infoOnLocalTimeSince1601Val(buf, "        EndDate:", this.endMinsSince1601);
/*     */     
/* 192 */     infoOnLocalTimeSince1601Val(buf, "        OriginalStartDate:", this.origStartMinsSince1601);
/*     */     
/* 194 */     buf.append("        OverrideFlags:").append(this.overrideFlags).append("\n");
/*     */     
/* 196 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_SUBJECT)) {
/* 197 */       buf.append("        Subject:").append(this.subject).append("\n");
/*     */     }
/* 199 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_MEETINGTYPE)) {
/* 200 */       buf.append("        MeetingType:").append(this.meetingType).append("\n");
/*     */     }
/* 202 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_REMINDERDELTA)) {
/* 203 */       buf.append("        ReminderDelta:").append(this.reminderDelta).append("\n");
/*     */     }
/* 205 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_REMINDER)) {
/* 206 */       buf.append("        ReminderSet:").append(this.reminderSet).append("\n");
/*     */     }
/* 208 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_LOCATION)) {
/* 209 */       buf.append("        Location:").append(this.location).append("\n");
/*     */     }
/* 211 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_BUSYSTATUS)) {
/* 212 */       buf.append("        BusyStatus:").append(getBusyStatus());
/* 213 */       buf.append(" (").append(this.busyStatus).append(")\n");
/*     */     }
/* 215 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_ATTACHMENT)) {
/* 216 */       buf.append("        Attachment:").append(this.attachment).append("\n");
/*     */     }
/* 218 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_SUBTYPE)) {
/* 219 */       buf.append("        SubType:").append(this.subType).append("\n");
/*     */     }
/* 221 */     if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_APPTCOLOR)) {
/* 222 */       buf.append("        ApptColor:").append(this.apptColor).append("\n");
/*     */     }
/* 224 */     if (this.hasExtendedInfo) {
/* 225 */       if (this.hasChangeHighlight) {
/* 226 */         buf.append("        changeHLSize:").append(this.changeHighlightSize).append("\n");
/* 227 */         buf.append("        changeHLValue:").append(this.changeHighlightValue).append("\n");
/* 228 */         buf.append("        chgHLReserved:").append(TNEFUtils.toHexString((byte[])this.chgHLReserved, (int)this.changeHighlightSize - 4)).append("\n");
/*     */       }
/*     */       
/*     */ 
/* 232 */       if (this.rsrvBlockEE1Size != -1L) {
/* 233 */         buf.append("        rsrvBlockEE1Size:").append(this.rsrvBlockEE1Size).append("\n");
/* 234 */         if (this.rsrvBlockEE1Size != 0L) {
/* 235 */           buf.append("        rsrvBlockEE1:").append(TNEFUtils.toHexString((byte[])this.rsrvBlockEE1, (int)this.rsrvBlockEE1Size)).append("\n");
/*     */         }
/*     */       }
/*     */       
/*     */ 
/* 240 */       infoOnLocalTimeSince1601Val(buf, "        ExtendedStartDate:", this.eeStartMinsSince1601);
/*     */       
/* 242 */       infoOnLocalTimeSince1601Val(buf, "        ExtendedEndDate:", this.eeEndMinsSince1601);
/*     */       
/* 244 */       infoOnLocalTimeSince1601Val(buf, "        ExtendedOriginalStartDate:", this.eeOrigStartMinsSince1601);
/*     */       
/* 246 */       if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_SUBJECT)) {
/* 247 */         buf.append("        UnicodeSubjectLen:").append(this.unicodeSubjectLen).append("\n");
/* 248 */         buf.append("        UnicodeSubject:").append(this.unicodeSubject).append("\n");
/*     */       }
/* 250 */       if (this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_LOCATION)) {
/* 251 */         buf.append("        UnicodeLocationLen:").append(this.unicodeLocationLen).append("\n");
/* 252 */         buf.append("        UnicodeLocation:").append(this.unicodeLocation).append("\n");
/*     */       }
/* 254 */       if (this.rsrvBlockEE2Size != -1L) {
/* 255 */         buf.append("        rsrvBlockEE2Size:").append(this.rsrvBlockEE2Size).append("\n");
/* 256 */         if (this.rsrvBlockEE2Size != 0L) {
/* 257 */           buf.append("        rsrvBlockEE2:").append(TNEFUtils.toHexString((byte[])this.rsrvBlockEE2, (int)this.rsrvBlockEE2Size)).append("\n");
/*     */         }
/*     */       }
/*     */     }
/*     */     
/*     */ 
/* 263 */     return buf.toString();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public EnumSet<ExceptionInfoOverrideFlag> getOverrideFlags()
/*     */   {
/* 270 */     return this.overrideFlags;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public long getApptColor()
/*     */   {
/* 277 */     return this.apptColor;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public long getAttachment()
/*     */   {
/* 284 */     return this.attachment;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public BusyStatus getBusyStatus()
/*     */   {
/* 291 */     if (!this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_BUSYSTATUS)) {
/* 292 */       return null;
/*     */     }
/* 294 */     for (BusyStatus curr : BusyStatus.values()) {
/* 295 */       if (curr.mapiPropValue() == this.busyStatus) {
/* 296 */         return curr;
/*     */       }
/*     */     }
/* 299 */     return null;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public String getSummary()
/*     */   {
/* 307 */     if (this.unicodeSubject != null) {
/* 308 */       return this.unicodeSubject;
/*     */     }
/* 310 */     return this.subject;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public String getLocation()
/*     */   {
/* 318 */     if (this.unicodeLocation != null) {
/* 319 */       return this.unicodeLocation;
/*     */     }
/* 321 */     return this.location;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public long getMeetingType()
/*     */   {
/* 328 */     return this.meetingType;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public Integer getReminderDelta()
/*     */   {
/* 335 */     if (!this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_REMINDERDELTA)) {
/* 336 */       return null;
/*     */     }
/* 338 */     int newDelta = (int)this.reminderDelta;
/* 339 */     return Integer.valueOf(newDelta);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public Boolean getReminderSet()
/*     */   {
/* 346 */     if (!this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_REMINDER)) {
/* 347 */       return null;
/*     */     }
/* 349 */     return Boolean.valueOf(this.reminderSet != 0L);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public Boolean isAllDayEvent()
/*     */   {
/* 356 */     if (!this.overrideFlags.contains(ExceptionInfoOverrideFlag.ARO_SUBTYPE)) {
/* 357 */       return null;
/*     */     }
/* 359 */     return new Boolean(this.subType != 0L);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public DateTime getStartDate()
/*     */   {
/* 366 */     return IcalUtil.localMinsSince1601toDate(this.startMinsSince1601, this.tz);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public DateTime getEndDate()
/*     */   {
/* 373 */     return IcalUtil.localMinsSince1601toDate(this.endMinsSince1601, this.tz);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public DateTime getOriginalStartDate()
/*     */   {
/* 380 */     return IcalUtil.localMinsSince1601toDate(this.origStartMinsSince1601, this.tz);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public long getOrigStartMinsSince1601()
/*     */   {
/* 387 */     return this.origStartMinsSince1601;
/*     */   }
/*     */   
/*     */   private StringBuffer infoOnLocalTimeSince1601Val(StringBuffer buf, String desc, long localTimeSince1601)
/*     */   {
/* 392 */     if (localTimeSince1601 == -1L) {
/* 393 */       return buf;
/*     */     }
/* 395 */     buf.append(desc);
/* 396 */     buf.append(IcalUtil.friendlyLocalTime(localTimeSince1601, this.tz));
/* 397 */     buf.append(" (").append(IcalUtil.icalUtcTime(localTimeSince1601, this.tz));
/* 398 */     buf.append(") [");
/* 399 */     buf.append(localTimeSince1601);
/* 400 */     buf.append(" (0x");
/* 401 */     buf.append(Long.toHexString(localTimeSince1601));
/* 402 */     buf.append(")]\n");
/* 403 */     return buf;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/util/tnef/mapi/ChangedInstanceInfo.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */